#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
typedef pair < int , int > PII;
inline int read()
{
    int f = 1,x = 0;
    char ch = getchar();
    while(ch > '9' || ch < '0')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0',ch = getchar();
    return f * x;
}
int ans[114];
inline void write(int x)
{
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
    return;
}
int T,n,a[N],lr[N + 10],lb[N + 10];
void init(int i,int j)
{
    int lastr = N,lastb = N;
    while(j)
    {
        if(i & 1 == 1)
        {
            if(lastr == N)lastr = j;
            else
            {
                lr[lastr] = j;
                lastr = j;
            }
        }
        else
        {
            if(lastb == N)lastb = j;
            else
            {
                lb[lastb] = j;
                lastb = j;
            }
        }
        i >>= 1;
        j--;
    }
    return;
}
signed main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int hjy = 0;
    T = read();
    while(T--)
    {
        hjy++;
        int res = 0;
        n = read();
        for(int i = 1;i <= n;i++)
            a[i] = read();
        int state = (1 << n) - 1;
        for(int i = 1;i <= state;i++)
        {
            init(i,n);
            int cnt = 0;
            for(int j = 1;j <= n;j++)
            {
                if(i & (1 << (n - j)))
                {
                    if(a[j] == a[lr[j]]) cnt += a[j];
                }
                else
                {
                    if(a[j] == a[lb[j]]) cnt += a[j];
                }
            }
            res = max(cnt,res);
        }
        ans[hjy] = res;

    }
    for(int i = 1;i <= hjy;i++)
    {
        write(ans[i]);
        putchar('\n');
    }
    return 0;
}
